/*
 * @Author: your name
 * @Date: 2021-03-22 09:26:30
 * @LastEditTime: 2021-11-18 09:22:18
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \request\demo\webpack.config.js
 */
const fs = require('fs')
const path = require('path')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
	mode: 'development',

	// entry: fs.readdirSync(__dirname).reduce((entries, dir) => {
	//   const fullDir = path.join(__dirname, dir)
	//   console.log(fullDir)
	//   console.log(entries, dir)
	//   const entry = path.join(fullDir, 'index.js')
	//   if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) {
	//     entries[dir] = ['webpack-hot-middleware/client', entry]
	//   }

	//   return entries
	// }, {}),
	entry: path.resolve(__dirname, './index.js'),
	output: {
		path: path.join(__dirname, './dist'),
		filename: '[name].js',
		chunkFilename: '[id].chunk.js',
		publicPath: '/',
		// library: 'Http',
		library: "Http",
		libraryTarget: "umd"
	},
	module: {
		rules: [{
				test: /\.js$/,
				exclude: /node_modules/,
				use: ['babel-loader']
			},
			// {
			//   test: /\.vue$/,
			//   use: ['vue-loader']
			// },
			// {
			//   test: /\.css$/,
			//   use: ['vue-style-loader', 'css-loader']
			// }
		]
	},

	resolve: {
		alias: {
			'@/': path.resolve(__dirname, '../src'),
			checkBower: path.resolve(__dirname, '../src/getBrowser.js')
		}
	},

	optimization: {
		splitChunks: {
			cacheGroups: {
				vendors: {
					name: 'shared',
					filename: 'shared.js',
					chunks: 'initial'
				}
			}
		}
	},

	plugins: [
		// new VueLoaderPlugin(),
		new htmlWebpackPlugin({
			// chunks: ['index'],
			template: path.resolve(__dirname, './index.html')
		}),
		new webpack.HotModuleReplacementPlugin(),
		// new webpack.NoEmitOnErrorsPlugin(),
		// new webpack.DefinePlugin({
		//   __DEV__: JSON.stringify(true),
		//   'process.env': {
		//     NODE_ENV: JSON.stringify(process.env.NODE_ENV)
		//   }
		// })
	],

}